package stringregex;

/**
 * boolean matches(String regex):匹配
 * 使用给定的正则表达式（regex）验证当前字符串是否格式合法
 * 正确则返回true 错误返回false
 */
public class MatchesDemo {
    public static void main(String[] args) {
        String email = "1029213230@qq.com";
        //邮箱验证
        String regex = "[a-zA-Z0-9_]+@[a-zA-Z0-9]+(\\.[a-zA-Z]+)+";
        boolean match = email.matches(regex);
        System.out.println(match);
        if (match){
            System.out.println("对了");
        }else {
            System.out.println("不对");
        }
    }
}
